package com.qianda.qdminiapp.service.client;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

/**
 * 
 * @author gaigeshen
 * @since 12/27 2017
 */
public class JSONServiceResultParser implements ServiceResultParser {

  @Override
  public <T> ServiceResult<T> parse(String result, Class<T> dataType)
      throws ParseServiceResultException {
    
    try {
      return JSON.parseObject(result,
          new TypeReference<ServiceResult<T>>() { });
    } catch (Exception e) {
      throw new ParseServiceResultException("Could not parse service result from: " + result, e);
    }
  }

}
